package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.ActivityInfo;
import com.example.yuejian.yuejian.bean.ActivityList;
import com.example.yuejian.yuejian.bean.SignupActivity;
import com.example.yuejian.yuejian.service.ActivityService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/4.
 */

public class ActivityModel {
    private Retrofit retrofit;

    public ActivityModel() {
        retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();

    }
    //活动列表
    public void Activitylist(final ModleListListener listListener)
    {
        ActivityService service=retrofit.create(ActivityService.class);
        Call<List<ActivityList>>call=service.ActivityList();
        call.enqueue(new Callback<List<ActivityList>>() {
            @Override
            public void onResponse(Call<List<ActivityList>> call, Response<List<ActivityList>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<List<ActivityList>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    //活动详情
    public void ActivityInfo(int aid, final ModleListener listener)
    {
        ActivityService service=retrofit.create(ActivityService.class);
        Call<ActivityInfo>call=service.Activityinfo(aid);
        call.enqueue(new Callback<ActivityInfo>() {
            @Override
            public void onResponse(Call<ActivityInfo> call, Response<ActivityInfo> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<ActivityInfo> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    //活动报名
    public  void signupActivity(String activityid,String userid,int num,String username,
                                String  idcard,double money,String  pay_type,final ModleListener listener)
    {
        ActivityService service=retrofit.create(ActivityService.class);
        Call<SignupActivity>call=service.signupActive(activityid,userid,num,username,idcard,money,pay_type);
        call.enqueue(new Callback<SignupActivity>() {
            @Override
            public void onResponse(Call<SignupActivity> call, Response<SignupActivity> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<SignupActivity> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
